﻿/**
 * Created by xjchen on 2020-03-20.
 * */

#ifndef MIDDLEWARE_FILEWRITER_H
#define MIDDLEWARE_FILEWRITER_H


#include "DeviceWriter.h"

class FileWriter : public DeviceWriter {

public:
    ~FileWriter();

    /**
     * FileWriter
     * 
     * @param filePath 输出文件路径
     * @param dynamic 是否为运行时动态创建的动态Writer
     */
    FileWriter(std::string filePath, bool dynamic = false);

    FLOW_API void setLimit(int maxFileSizeInMB, int numberOfFiles);

    int64_t onWrite(char *buffer, int64_t len) override;

    void stop() override;

private:
    FILE *fp = nullptr;
    std::string filePath;
    bool dynamic = false;
    int counter;
    int64_t currentFileSize;
    int64_t maxFileSize = -1l;
    int numberOfFiles = 1;
};


#endif /** MIDDLEWARE_FILEWRITER_H */
